package com.ruoyi.web.controller.module.product;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.system.domain.module.product.OrderAppraise;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.module.product.IOrderAppraiseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 评价Controller
 *
 * @author ruoyi
 * @date 2021-08-24
 */
@Validated
@Api(value = "评价控制器", tags = {"评价管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/module/product/appraise")
public class OrderAppraiseController extends BaseController {

    private final IOrderAppraiseService orderAppraiseService;

    /**
     * 查询评价列表
     */
    @ApiOperation("查询评价列表")
    @PreAuthorize("@ss.hasPermi('module:appraise:list')")
    @GetMapping("/list")
    public TableDataInfo<OrderAppraise> list(@Validated OrderAppraise orderAppraise) {
        return PageUtils.buildDataInfo(orderAppraiseService.page(PageUtils.buildPage()));
    }

    /**
     * 导出评价列表
     */
    @ApiOperation("导出评价列表")
    @PreAuthorize("@ss.hasPermi('module:appraise:export')")
    @Log(title = "评价", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<OrderAppraise> export(@Validated OrderAppraise orderAppraise) {
        List<OrderAppraise> list = orderAppraiseService.list();
        ExcelUtil<OrderAppraise> util = new ExcelUtil<OrderAppraise>(OrderAppraise.class);
        return util.exportExcel(list, "评价");
    }

    /**
     * 获取评价详细信息
     */
    @ApiOperation("获取评价详细信息")
    @PreAuthorize("@ss.hasPermi('module:appraise:query')")
    @GetMapping("/{id}")
    public AjaxResult<OrderAppraise> getInfo(@NotNull(message = "主键不能为空") @PathVariable("id") Long id) {
        OrderAppraise orderAppraise = orderAppraiseService.getById(id);
        return AjaxResult.success(orderAppraise);
    }

    /**
     * 新增评价
     */
    @ApiOperation("新增评价")
    @PreAuthorize("@ss.hasPermi('module:appraise:add')")
    @Log(title = "评价", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody OrderAppraise orderAppraise) {
        return toAjax(orderAppraiseService.save(orderAppraise) ? 1 : 0);
    }

    /**
     * 修改评价
     */
    @ApiOperation("修改评价")
    @PreAuthorize("@ss.hasPermi('module:appraise:edit')")
    @Log(title = "评价", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody OrderAppraise orderAppraise) {
        return toAjax(orderAppraiseService.updateById(orderAppraise) ? 1 : 0);
    }

    /**
     * 删除评价
     */
    @ApiOperation("删除评价")
    @PreAuthorize("@ss.hasPermi('module:appraise:remove')")
    @Log(title = "评价" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")  @PathVariable Long[] ids) {
        return toAjax(orderAppraiseService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
